<template>
  <div v-loading.lock="loading" class="base-content">
    <div class="basic-info">
      <el-form ref="queryForm" :inline="true" :model="queryForm">
        <el-form-item label="任务编号" prop="EntrustTaskNum">
          <el-input v-model="queryForm.EntrustTaskNum" placeholder="任务编号" />
        </el-form-item>
        <el-form-item label="委托单号" prop="EntrustOrderNum">
          <el-input
            v-model="queryForm.EntrustOrderNum"
            placeholder="委托单号"
          />
        </el-form-item>
        <el-form-item label="样品编号" prop="SampleNum">
          <el-input v-model="queryForm.SampleNum" placeholder="样品编号" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getList('filter')">查询</el-button>
          <el-button @click="cancelForm">清空</el-button>
        </el-form-item>
      </el-form>
      <!-- <div class="base-content-operate">
        <el-button type="primary" icon="el-icon-document-copy">导出</el-button>
      </div> -->
      <el-table
        :data="list"
        element-loading-text="Loading"
        fit
        highlight-current-row
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="任务编号">
          <template slot-scope="scope">
            {{ scope.row.entrustTaskNum }}
          </template>
        </el-table-column>
        <el-table-column label="检测项目">
          <template slot-scope="scope">
            {{ scope.row.detectionItemName }}
          </template>
        </el-table-column>
        <el-table-column label="委托单号">
          <template slot-scope="scope">
            {{ scope.row.entrustOrderNumList }}
          </template>
        </el-table-column>
        <el-table-column label="样品名称">
          <template slot-scope="scope">
            {{ scope.row.sampleInfoName }}
          </template>
        </el-table-column>
        <el-table-column label="样品编号">
          <template slot-scope="scope">
            {{ scope.row.sampleInfoNum }}
          </template>
        </el-table-column>

        <el-table-column v-if="systemType == 'thirdparty'" label="实验记录单">
          <template slot-scope="scope">
            {{ scope.row.experimentRecordOrderCount }}
          </template>
        </el-table-column>
        <el-table-column label="检测日期">
          <template slot-scope="scope">
            {{ formatTime(scope.row.experimentRecordDate) }}
          </template>
        </el-table-column>
        <el-table-column label="分配检测人">
          <template slot-scope="scope">
            {{ scope.row.detectionPersonName }}
          </template>
        </el-table-column>
        <el-table-column label="分配时间">
          <template slot-scope="scope">
            {{ formatTime(scope.row.planDetectionDate) }}
          </template>
        </el-table-column>
        <el-table-column label="实际接收人">
          <template slot-scope="scope">
            {{ scope.row.receivePersonName }}
          </template>
        </el-table-column>
        <el-table-column label="接收时间">
          <template slot-scope="scope">
            {{ formatTime(scope.row.receiveDate) }}
          </template>
        </el-table-column>
        <el-table-column label="任务状态">
          <template slot-scope="scope">
            {{ scope.row.entrustTaskStatusChar }}
          </template>
        </el-table-column>

        <el-table-column label="备注">
          <template slot-scope="scope">
            {{ scope.row.remark }}
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <BasePagination
        :total="pagination.total"
        :page-index="pagination.pageIndex"
        :page-size="pagination.pageSize"
        @sizeChange="sizeChange"
        @changePage="currentChange"
      />
    </div>
  </div>
</template>

<script>
import { entrustTaskNoticedList } from "../../../api/EntrustTaskManage/EntrustTask.js";
import { getConfigByKey } from "../../../api/System/SystemDict";
import { formatTime } from "../../../utils/time";
export default {
  name: "EntrustTaskNoticed",
  data() {
    return {
      formatTime,
      tableDatas: [],
      loading: true,
      list: [],
      queryForm: {
        EntrustOrderNum: "",
        EntrustTaskNum: "",
        SampleNum: ""
      },
      dialogFormVisible: false,
      pagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
      systemType: "",
    };
  },
  created() {
    // 查询字典表判断系统类型
    getConfigByKey("SystemType").then((res) => {
      this.systemType = res.data[0].value;
    });
    this.getList("filter");
  },
  methods: {
    currentChange(val) {
      this.pagination.pageIndex = val;
      this.getList();
    },
    sizeChange(val) {
      this.pagination.pageIndex = 1;
      this.pagination.pageSize = val;
      this.getList("filter");
    },
    getList(flag) {
      if (flag) {
        this.pagination.pageIndex = 1;
      }
      this.loading = true;
      this.entrustTaskNoticedListFun({
        ...this.queryForm,
        ...this.pagination,
      });
    },
    entrustTaskNoticedListFun(obj) {
      this.list = [];
      entrustTaskNoticedList(obj)
        .then((res) => {
          if (res.code === 200) {
            if (res.data.dataList.length <= 0) {
              return;
            }
            this.pagination.total = res.data.total;
            for (var j = 0; j < res.data.dataList.length; j++) {
              var obj = {};
              // 实验记录单数量
              obj.experimentRecordOrderCount =
                res.data.dataList[j].experimentRecordOrderCount;
              obj.entrustTaskNum = res.data.dataList[j].entrustTaskNum; // 任务编号
              obj.detectionItemName = res.data.dataList[j].detectionItemName; // 检测项目
              obj.entrustOrderNumList =
                res.data.dataList[j].entrustOrderNumList; // 委托单号
              obj.sampleInfoName = res.data.dataList[j].sampleInfoName; // 样品名称
              obj.sampleInfoNum = res.data.dataList[j].sampleInfoNum; // 样品编号
              obj.experimentRecordOrder = ""; // 实验记录单
              obj.experimentRecordDate =
                res.data.dataList[j].experimentRecordDate; // 检测日期
              obj.detectionPersonName =
                res.data.dataList[j].detectionPersonName; // 分配检测人
              obj.planDetectionDate = res.data.dataList[j].planDetectionDate; // 分配时间
              obj.receivePersonName = res.data.dataList[j].receivePersonName; // 实际接收人
              obj.receiveDate = res.data.dataList[j].receiveDate; // 接收时间
              obj.entrustTaskStatusChar =
                res.data.dataList[j].entrustTaskStatusChar; // 任务状态
              obj.remark = res.data.dataList[j].remark; // 备注
              this.list.push(obj);
            }

            this.loading = false;
          }
        })
        .catch((res) => {
          this.loading = false;
        });
    },

    onQuery() {
      this.getList();
    },
    handleSelectionChange(val) {
      this.tableDatas = val;
    },
    // 清空筛选条件
    cancelForm() {
      this.$refs.queryForm.resetFields();
      this.getList("filter");
    },
  },
};
</script>
